home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / amiga / programmer / 7231 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.3 KB

  1. Path: lou.teclink.net!usenet
  2. From: rad@TECLink.net (rad)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Re: unsigned long addition question(GDS)
  5. Date: 12 Apr 1996 03:41:14 GMT
  6. Organization: TECLink Internet Services: info@TECLink.Net
  7. Message-ID: <1984.6675T1353T2973@TECLink.net>
  8. References: <1052.6674T364T2106@infi.net>
  9. NNTP-Posting-Host: tc1_15.teclink.net
  10. X-Newsreader: THOR 2.22 (Amiga;TCP/IP) *UNREGISTERED*
  11.  
  12. On 10-Apr-96 04:27:07, DHopkins <dhopkins@infi.net> wrote:
  13. >I'm using Gamesmith with SAS/C and have run into a complete
  14. >blank in my math knowledge. GDS uses an 8-bit color table
  15. >eg. 0x00rrggbb. Usually, I just ignore this type of stuff
  16. >but now it's hit me square in the face.
  17.  
  18. >I want to do a screen fade and figured that I'd use the
  19. >gs_SetRGB function to fade each color. the Commodore
  20. >version of SetRGB32 lets you enter a value for r, g, and b.
  21. >But gs_SetRGB only has 1 variable for the color, and it
  22. >has r,g,b embedded in it.(like I said, 0x00rrggbb). How
  23. >can I subtract from just r,g or b?
  24. >
  25. >I don't think I can do this...
  26. >
  27. >n=0x00rrggbb
  28. >n--
  29.  
  30. correct, it won't work right for red & green.
  31.  
  32. >but what about...
  33. >
  34. >n = 0x00rrggbb - 0x000001  (to subtract from b)
  35. >
  36. >n = 0x00rrggbb - 0x00010000 (to subtract from r)
  37.  
  38. You could do this, but you must make sure that you don't underflow any of the
  39. fields.  For example:
  40.  
  41.  n = 0x00000000 -0x00000100 gives you 0xffffff00... changing red & green.
  42.  
  43. You would probably be better off using a union to break up you're number:
  44.  
  45.    union rgb_conv_T {
  46.       long long_format;
  47.       struct {
  48.          char unused;  /* MSB */
  49.          char red;
  50.          char green;
  51.          char blue;    /* LSB */
  52.       } short_format;
  53.    } convertor;
  54.  
  55. Then you could do:
  56.  
  57.    convertor.long_format = /* get a color ... */
  58.  
  59.    convertor.short_format.red--;
  60.    convertor.short_format.green--;
  61.    convertor.short_format.blue--;
  62.    /* or whatever you needed to do */
  63.  
  64.    /* save new color */ = convertor.long_format;
  65.  
  66. This should work as long as you stick to the Amiga.  ;)
  67.  
  68.  
  69. ---------------------------------------------------------------------------
  70. - Richard Deken                         EMail: (personal) rad@teclink.net -
  71. - VLSI Design Engineer                         (AuE)      rad@aue.com     -
  72. - Advanced Microelectronics             PGP public key available          -
  73. ---------------------------------------------------------------------------
  74.  
  75.